/** @file               sw_json.h
 *  @copyright          Copyright (C) 2006-2026 flyfish (tenggui_fu@126.com)
 *  @brief              This file is part of the swallow library
 *  @author             $Author: flyfish $
 *  @version            $Rev: 385 $
 *  @date               $Date: 2016-12-22 00:12:05 +0800 (周四, 22 12月 2016) $
 */
#ifndef __SW_JSON_H__
#define __SW_JSON_H__

#ifdef __cplusplus
extern "C" {
#endif

typedef SW_VOID             *SW_JSON;
#define SW_INVALID_JSON     NULL

typedef enum _SW_JSON_TYPE
{
    SW_JT_NULL,
    SW_JT_BOOL,
    SW_JT_DOUBLE,
    SW_JT_INT,
    SW_JT_OBJ,
    SW_JT_ARRAY,
    SW_JT_STR,
    SW_JT_INVALID = -1
}SW_JSON_TYPE;

SW_API SW_RET SW_InitJsonAPI(SW_VOID);
SW_API SW_RET SW_RunJsonAPI(SW_VOID);
SW_API SW_RET SW_StopJsonAPI(SW_VOID);
SW_API SW_RET SW_ExitJsonAPI(SW_VOID);
SW_API SW_JSON SW_OpenJson(const SW_CHAR *pFileName);
SW_API SW_JSON SW_LoadJson(const SW_CHAR *pJsonStr);
SW_API SW_JSON SW_CreateJson(SW_VOID);
SW_API SW_RET SW_CloseJson(SW_JSON json);
SW_API SW_JSON SW_CloneJson(SW_JSON json);
SW_API SW_RET SW_SaveJson(SW_JSON json, const SW_CHAR *pFileName, SW_BOOL format);
SW_API SW_JSON SW_CreateJsonInt8(SW_INT8 value);
SW_API SW_JSON SW_CreateJsonUInt8(SW_UINT8 value);
SW_API SW_JSON SW_CreateJsonInt16(SW_INT16 value);
SW_API SW_JSON SW_CreateJsonUInt16(SW_UINT16 value);
SW_API SW_JSON SW_CreateJsonInt(SW_INT value);
SW_API SW_JSON SW_CreateJsonUInt(SW_UINT value);
SW_API SW_JSON SW_CreateJsonInt32(SW_INT32 value);
SW_API SW_JSON SW_CreateJsonUInt32(SW_UINT32 value);
SW_API SW_JSON SW_CreateJsonInt64(SW_INT64 value);
SW_API SW_JSON SW_CreateJsonUInt64(SW_UINT64 value);
SW_API SW_JSON SW_CreateJsonBool(SW_BOOL value);
SW_API SW_JSON SW_CreateJsonFloat(SW_FLOAT value);
SW_API SW_JSON SW_CreateJsonDouble(SW_DOUBLE value);
SW_API SW_JSON SW_CreateJsonStr(const SW_CHAR *pStr);
SW_API SW_JSON SW_CreateJsonArray(SW_VOID);
SW_API SW_RET SW_AddJsonArrayItem(SW_JSON array, SW_JSON item);
SW_API SW_RET SW_SetJsonArrayItem(SW_JSON array, SW_UINT32 index, SW_JSON item);
SW_API SW_UINT32 SW_GetJsonArrayItemCount(SW_JSON array);
SW_API SW_JSON SW_GetJsonArrayItem(SW_JSON array, SW_UINT32 index);
SW_API SW_RET SW_SetJsonItem(SW_JSON json, const SW_CHAR *pKey, SW_JSON item);
SW_API SW_JSON SW_GetJsonItem(SW_JSON json, const SW_CHAR *pKey);
SW_API SW_RET SW_DeleteJsonItem(SW_JSON json, const SW_CHAR *pKey);
SW_API SW_INT8 SW_GetJsonInt8(SW_JSON json);
SW_API SW_UINT8 SW_GetJsonUInt8(SW_JSON json);
SW_API SW_INT16 SW_GetJsonInt16(SW_JSON json);
SW_API SW_UINT16 SW_GetJsonUInt16(SW_JSON json);
SW_API SW_INT SW_GetJsonInt(SW_JSON json);
SW_API SW_UINT SW_GetJsonUInt(SW_JSON json);
SW_API SW_INT32 SW_GetJsonInt32(SW_JSON json);
SW_API SW_UINT32 SW_GetJsonUInt32(SW_JSON json);
SW_API SW_INT64 SW_GetJsonInt64(SW_JSON json);
SW_API SW_UINT64 SW_GetJsonUInt64(SW_JSON json);
SW_API SW_BOOL SW_GetJsonBool(SW_JSON json);
SW_API SW_FLOAT SW_GetJsonFloat(SW_JSON json);
SW_API SW_DOUBLE SW_GetJsonDouble(SW_JSON json);
SW_API const SW_CHAR *SW_GetJsonStr(SW_JSON json);
SW_API const SW_CHAR *SW_GetJsonRawStr(SW_JSON json);
SW_API SW_CHAR *SW_FormatJsonRawStr(const SW_CHAR *pStr);
SW_API SW_JSON_TYPE SW_GetJsonType(SW_JSON json);
SW_API const SW_CHAR *SW_JsonTypeToStr(SW_JSON_TYPE type);
SW_API SW_RET SW_GetFirstJsonItem(SW_JSON json, SW_CHAR **pKey, SW_JSON *pItem, SW_VOID **pData);
SW_API SW_RET SW_GetLastJsonItem(SW_JSON json, SW_CHAR **pKey, SW_JSON *pItem, SW_VOID **pData);
SW_API SW_RET SW_GetNextJsonItem(SW_JSON json, SW_CHAR **pKey, SW_JSON *pItem, SW_VOID **pData);
SW_API SW_RET SW_GetPrevJsonItem(SW_JSON json, SW_CHAR **pKey, SW_JSON *pItem, SW_VOID **pData);
SW_API SW_UINT32 SW_GetJsonItemCount(SW_JSON json);
SW_API SW_RET SW_GetJsonItemAt(SW_JSON json, SW_UINT32 index, SW_CHAR **pKey, SW_JSON *pItem);
SW_API SW_JSON SW_GetJsonItemRecursively(SW_JSON json, const SW_CHAR *pKey, SW_BOOL newItem);

#ifdef __cplusplus
}
#endif

#endif

